package com.liuhouse.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//标识为配置类
@Configuration
//开启swagger,即可以通过swagger为liuhouse-blog工程生成接口文档
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createTestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //对所有的api进行监控
                .apis(RequestHandlerSelectors.any())
                //不显示错误的接口地址,也就是错误路径不监控 , 这是人家规定好的  咱只需要遵守就行了
                .paths(Predicates.not(PathSelectors.regex("/error.*"))).build();
    }


    //指定头部信息
    private ApiInfo apiInfo(){
        Contact contact = new Contact("liuhouse的开发团队", "1312797840@qq.com", "http://www.xiaobangcai.com");
        return new ApiInfoBuilder()
                .title("博客文档")
                .description("前端接口文档")
                .contact(contact)//联系方式
                .version("1.0.0")//版本
                .build();


    }

}
